package TEST4_21;

public class T3{

    private double money;
    public T3(double money) {
        this.money = money;
    }

    public synchronized void putMoney(){
        double a = Math.random()*1000;
        this.money = this.money + a;
        System.out.println("现在有："+ this.money +"元");
    }

    public synchronized void getMoney(){
        double b = Math.random()*1000;
        if (this.money<b){
            System.out.println("取款失败，余额不足");
        }else {
            this.money = this.money - b;
            System.out.println("现在有："+ this.money +"元");
        }
    }
}

class test {
    public static void main(String[] args) {
        T3 test = new T3(1);
        //new Thread(()->test.getMoney()).start();

        new Thread(() -> {test.putMoney();}).start();
        new Thread(() -> {test.getMoney();}).start();
    }
}
